package com.ocean.service.edu.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ocean.dao.edu.StudentDao;
import com.ocean.dao.edu.TClassDao;
import com.ocean.dto.TclassDto;
import com.ocean.entity.edu.Student;
import com.ocean.entity.edu.TClass;
import com.ocean.service.edu.StudentService;
import com.ocean.service.edu.TClassService;
import com.ocean.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author greenbird
 * @create 2023-03-04 15:47
 */
@Service
public class TClassServiceImpl implements TClassService {
    @Autowired
    private TClassDao dao;

    @Override
    public R save(TClass obj) {
        if(dao.insert(obj)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R delete(int id) {
        if(dao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(TClass obj) {
        if(dao.update(obj)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R queryPage(String classname,String classnum,int page,int size) {
        PageHelper.startPage(page, size);
        PageInfo<TClass> pageInfo=new PageInfo<>(dao.selectWhere(classname,classnum));
        return R.ok(pageInfo);
    }

    @Override
    public R queryEcharts() {
        //1.查询数据
        List<TclassDto> list=dao.selectNum();
        //2.组装数据
        Map<String, ArrayList> map=new HashMap<>();
        map.put("classid",new ArrayList<String>());
        map.put("cnum",new ArrayList());
        list.forEach(d->{
            map.get("classid").add(d.getClassid()+"班");
            map.get("cnum").add(d.getCnum());
        });
        return R.ok(map);
    }


}
